#include <iostream>
#include <stack>
#include <vector>
using namespace std;
class CQueue
{
public:
    CQueue(){
        stack1 = new stack<int>();
        stack2 = new stack<int>();
    }
    void appendTail(int value)
    {
        stack1->push(value);
    }

    int deleteHead()
    {

        if(stack2->empty())
        {
            if(stack1->empty())
            {
                return -1;
            }
            else {
                while (!stack1->empty()) {
                    stack2->push(stack1->top());
                    stack1->pop();
                }
            }
        }

            int item = stack2->top();
            stack2->pop();
            return item;

    }
    void append(vector<int> vec)
    {
        for(vector<int>::iterator it = vec.begin(); it != vec.end(); it++)
        {
            appendTail(*it);
        }
    }
private:
    stack<int>* stack1;
    stack<int>* stack2;
};

class MinStack {
public:
    /** initialize your data structure here. */
    MinStack() {
        m_stack = new stack<int>;
        min_stack = new stack<int>;
    }
    void push(int x) {
        // if(!m_stack->empty())
        // {
        //     if(min_stack->top() < x)
        //         min_stack->push(min_stack->top());
        //     else
        //         min_stack->push(x);
        //     m_stack->push(x);
        //     return;
        // }
        m_stack->push(x);
        // min_stack->push(x);
        min_stack->push(std::min(min_stack->top(), x));
        // min_stack->push(min(x, min_stack->top()));
    }

    void pop() {
        m_stack->pop();
        min_stack->pop();
    }

    int top() {
        return m_stack->top();
    }

    int min() {
        return min_stack->top();
    }
private:
    stack<int>* m_stack;
    stack<int>* min_stack;


};

void append( vector<int> )
{

}
void test()
{
    CQueue queue;
    for(int i = 0; i <= 5; i++)
    {
        queue.appendTail(i);
    }
    while(1)
    {
        int deleteitem = queue.deleteHead();
        cout<<deleteitem <<endl;
        if(deleteitem == -1)
            return;
    }
}


void test2()
{
    vector<int> vec(8,3) ;
    CQueue queue;
    queue.append(vec);
    while(1)
    {
        int deleteitem = queue.deleteHead();
        cout<<deleteitem <<endl;
        if(deleteitem == -1)
            return;
    }
}
void test3()
{
    MinStack minstack;
    minstack.push(4);
    minstack.push(5);
    cout<<minstack.min()<<endl;
}
int main()
{
    vector<int> ss;

    test3();
}
